package com.wordsay.web.analyst;

import com.wordsay.common.Constant;
import com.wordsay.context.Context;
import com.wordsay.context.Resource;
import com.wordsay.core.Wordsay;
import com.wordsay.entity.OverallAnalystResult;

public class WordsayAnalyst {

	/**
	 * execute wordsay analyst in web context
	 */
	public void execute() throws Exception{
		
		Wordsay wordsay = new Wordsay();
		try{
		if(wordsay.parseChatRecord(Context.getInstance().getContextMap().get("wordsPath"), Constant.CHAT_APP_FEIXIN)){
			
			Resource resource = Context.getInstance().getResource(); 
					
			//执行全局分析
			OverallAnalystResult analyRes = (OverallAnalystResult)wordsay.executeOverallAnalyst();
			analyRes.printResult();
			
			resource.setOverallAnalystResult(analyRes);
			
			long start= System.currentTimeMillis();
			//执行个性分析（针对具体聊天的人）
			//分析单人聊天
			wordsay.executePersonsAnalyst();
			
			//分析群组聊天
			wordsay.executeGroupsAnalyst();
			
			//分析讨论组聊天
			wordsay.executeDiscussionsAnalyst();
			
			System.out.println("analyst hot words and periods spent:"+(System.currentTimeMillis() - start) / 1000+"ms");
			
			start= System.currentTimeMillis();
			//分析人与人的聊天相似度
			wordsay.executePersonSimilarAnalyst();
			
			System.out.println("analyst person similar spent:"+(System.currentTimeMillis() - start)+"ms");
		}
		}catch(Exception e){
			e.printStackTrace();
			throw e;
		}
	}
}
